package GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import Client.Client;

public class CreateFrame extends JFrame implements ActionListener {
	// Variabelbös
	JTextField doctorField, nurseField, patientField, commentField,
			patientIDField;
	Client client;
	JButton exitButton, createButton;

	public CreateFrame(Client client, String dataString) {
		super("Create journal");

		String[] temp;
		String delimiter = "#";
		temp = dataString.split(delimiter);

		setVisible(true);
		this.setSize(500, 100);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.client = client;

		setLayout(new GridLayout(6, 2));

		// lägg till bös i listan;

		doctorField = new JTextField("");
		add(new JLabel("Doctor"));
		add(doctorField);

		nurseField = new JTextField("");
		add(new JLabel("Nurse:"));
		add(nurseField);

		patientField = new JTextField("");
		add(new JLabel("Patient:"));
		add(patientField);

		patientIDField = new JTextField("");
		add(new JLabel("PatientID"));
		add(patientIDField);

		commentField = new JTextField("");
		add(new JLabel("Comment:"));
		add(commentField);

		exitButton = new JButton("Exit");
		createButton = new JButton("Create");
		add(exitButton);
		add(createButton);
		pack();

		exitButton.addActionListener(this);
		createButton.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == createButton) {
			client.sendText("new_list", doctorField.getText(), nurseField
					.getText(), commentField.getText(), patientIDField
					.getText());
		}

		new JournalFrame(client);
		this.setVisible(false);
	}

	public void warningMessage(String s) {
		System.out.print(s);
	}
}
